#ifndef _SPI_H_
#define _SPI_H_

#include "include/gpiodef_f003.h"
#include "include/ca51f003xsfr.h"
#include "include/ca51f003sfr.h"

//软件模拟SPI
#define SPI_CS P03
#define SPI_SCK P01
#define SPI_MISO P10
#define SPI_MOSI P00

//fifodata_reg:0x09
#define wfifoaddr   (0x09 << 1) & 0x7e
#define rfifoaddr   (0x09 << 1) | 0x80

void spi_init(void);
void spi_sendbyte(unsigned char val);
unsigned char spi_recbyte(void);
unsigned char spi_swapbyte(unsigned char val);
void spi_write_reg(unsigned char addr, unsigned char val);
unsigned char spi_read_reg(unsigned char addr);
void spi_write_fifo(unsigned char*val,unsigned char len);
void spi_read_fifo(unsigned char *val,unsigned char len);

#endif
